package com.example.shilehui;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import cn.jhc.service.ContactService;
import cn.jhc.service.HelpTopicDataService;
import cn.jhc.service.PersonInfoService;
import cn.jhc.utils.SharedMethod;


public class ReceiptInfoActivity extends Activity {
	
	
	 private TextView _titleTextView;
	 private ImageView _backImageView;
	 private TextView _titleRightTextView;
	 private ImageView _titleRightImageView;
	 private Dialog _dialog;
	 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		 DownloadJson task=new DownloadJson();
	     task.execute();
		
	}
	
	private void init(){
		
		
		setContentView(R.layout.receipt_info_layout);
		
		setTitleStyle();
	}
	
	private void setTitleStyle(){
		 _titleTextView=(TextView)findViewById(R.id.title_middle);
		 _backImageView=(ImageView)findViewById(R.id.title_left_imageview);
		 _titleRightTextView=(TextView)findViewById(R.id.title_right_textview);
		 _titleRightImageView=(ImageView)findViewById(R.id.title_right_imageview);
		 
		 
		 _titleTextView.setText(R.string.person_receipt_detail);
		 _titleTextView.setTextColor(Color.WHITE);
		 _titleTextView.setTextSize(18);
		 _titleTextView.setGravity(Gravity.CENTER);
		 
		 
		 _backImageView.setImageResource(R.drawable.left_icon);
		 _backImageView.setOnClickListener(new onViewClickListener());
		 _titleRightImageView.setVisibility(View.GONE);
		 _titleRightTextView.setVisibility(View.GONE);
	}
	
	 private class onViewClickListener implements OnClickListener{

			@Override
			public void onClick(View v) {
				switch(v.getId()){
					case R.id.title_left_imageview:
						finish();
						break;
				}
				
			}
			 
	}
	 
	 private class DownloadJson extends AsyncTask<Void,Void,String>{
			
			
		 	
		 	
			@Override
		protected void onPreExecute() {
			super.onPreExecute();
			
			_dialog=new Dialog(ReceiptInfoActivity.this);
			_dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
			_dialog.setContentView(R.layout.jump_progressbar_white_layout);
			_dialog.show();
			
		}

			@Override
			protected String doInBackground(Void... params) {
				try {
					Thread.sleep(500);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				String titleId=HelpTopicDataService.getInstance().getTitleId();
			//	String result=HelpTopicDataService.getInstance().connServerForResult(getUrl(titleId));
				
				String result=ContactService.getInstance().getJSONData(getUrl(titleId));
				return result;
			}
			
			@Override  

	        protected void onPostExecute(String result) {  
			
				 super.onPostExecute(result);  
				 
				 if(PersonInfoService.getInstance().parseJsonReceiptInfo(result)){
					 _dialog.dismiss();
				     init();   
				 }else{
					 
					 SharedMethod.getInstance().showTextToast(SharedMethod.getInstance().getNoData(), ReceiptInfoActivity.this);
				 }
				 

	        } 
		 
		 } 
	 
	 private String getUrl(String id){
		 String url="http://app.shilehui.com/WebService/Assist.aspx?auction=GetAssistReceiptHelpInfoByID&sign=3D72C48B786A70B7A9D16E3AA1382565&AssistID="+id;
		 return url;
	 }
}
